package com.briup.pts.web.controller;

import com.briup.pts.aop.Logger;
import com.briup.pts.config.response.Result;
import com.briup.pts.domain.bean.Disease;
import com.briup.pts.domain.bean.DiseaseRecord;
import com.briup.pts.domain.vo.DiseaseRecordVO;
import com.briup.pts.service.DiseaseRecordService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "病症记录模块")
@RestController
@RequestMapping("/diseaseRecord")
@RequiredArgsConstructor
public class DiseaseRecordController {
    private final DiseaseRecordService diseaseRecordService;

    @Operation(summary = "查询所有病症类型信息")
    @GetMapping("/queryAllDisease")
    public Result<List<Disease>> queryAllDisease(){
       return Result.success(diseaseRecordService.queryAllDisease());
    }

    @Operation(summary = "分页多条件查询病症记录")
    @GetMapping("/query")
    public Result<?> PageQuery(
            @RequestParam(defaultValue = "1")
            @Min(value = 1,message = "当前页码不能小于1")Integer pageNum,
            @RequestParam(defaultValue = "5")
            @Min(value = 1,message = "当前页码不能小于1")Integer pageSize,
            String drDId, String drStatus){

        PageInfo<DiseaseRecordVO> pageInfo = diseaseRecordService
                .pageQuery(drDId,drStatus,pageNum,pageSize);
        return Result.success(pageInfo);
    }

    @Logger("根据记录ID删除病症记录接口")
    @Operation(summary = "根据记录ID删除病症记录接口")
    @DeleteMapping("/deleteById/{drId}")
    public Result<?> deleteById(@PathVariable("drId") Integer drId){
        diseaseRecordService.batchDelete(List.of(drId));
        return Result.success();
    }

    @Logger("批量删除病症记录接口")
    @Operation(summary = "批量删除病症记录接口")
    @DeleteMapping("/deleteByIdAll")
    public Result<?> deleteById(@RequestBody @NotEmpty(message = "待删除的指标记录id必须指定") List<Integer> drIds){
        diseaseRecordService.batchDelete(drIds);
        return Result.success();
    }

    @Logger("新增或更新病症记录接口")
    @Operation(summary = "新增或更新病症记录接口")
    @PostMapping("/saveOrUpdate")
    public Result<?> saveOrUpdate(@RequestBody @Validated DiseaseRecord diseaseRecord){
        diseaseRecordService.saveOrUpdate(diseaseRecord);
        return Result.success();
    }

}

